package com.lu.library.kv

import com.blankj.utilcode.util.LogUtils

interface KV {
    fun init(name: String)

    fun getInt(key: String, defaultValue: Int): Int

    fun getLong(key: String, defaultValue: Long): Long

    fun getFloat(key: String, defaultValue: Float): Float

    fun getBoolean(key: String, defaultValue: Boolean): Boolean

    fun getString(key: String, defaultValue: String): String?

    fun putString(key: String, defaultValue: String)

    fun putInt(key: String, defaultValue: Int)

    fun putLong(key: String, defaultValue: Long)

    fun putFloat(key: String, defaultValue: Float)

    fun putBoolean(key: String, defaultValue: Boolean)
    fun get(key:String,defaultValue: Any):Any?{
        return when(defaultValue){
            is Int -> getInt(key, defaultValue)
            is String -> getString(key, defaultValue)
            is Boolean -> getBoolean(key, defaultValue)
            is Float -> getFloat(key, defaultValue)
            is Long -> getLong(key, defaultValue)
            else -> null
        }
    }
    fun put(key: String, value: Any) {
        LogUtils.d("key:$key,v:$value")
        when (value) {
            is Int -> putInt(key, value)
            is String -> putString(key, value)
            is Boolean -> putBoolean(key, value)
            is Float -> putFloat(key, value)
            is Long -> putLong(key, value)
            else -> LogUtils.e("value:$value")
        }
    }

    fun remove(key: String)

    fun clear()
    fun getAll(): MutableMap<String, *>

    fun getKeys(): List<String>

    fun containsKey(key: String): Boolean
}